package com.aidong.carnival.controllers;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aidong.activity.biz.MstCampaignBiz;
import com.aidong.carnival.controllers.concerns.Failure;
import com.aidong.carnival.controllers.concerns.Result;
import com.aidong.carnival.controllers.concerns.Success;
import com.aidong.carnival.controllers.concerns.View;
import com.aidong.carnival.service.AllCampaignService;
import com.aidong.food.biz.MstFoodBiz;
import com.aidong.stadium.biz.MstScheduleBiz;
import com.aidong.stadium.entity.MstConclusionabout;
import com.fasterxml.jackson.annotation.JsonView;

@RestController
@RequestMapping("/allCampaignHFive")
public class AllCampaignHFiveController {

	@Autowired
	AllCampaignService allCampaignService;
	
	@Autowired
	private MstCampaignBiz mstCampaignBiz; // 活动service
	
	@Autowired
	private MstScheduleBiz aboutScheduleBiz; // 团操service
	
	@Autowired
	private MstFoodBiz mstFoodBiz;
	
	@JsonView(View.Base.class)
	@RequestMapping(value = "/getHFive")
	public Result getHFive(@RequestParam(value = "ruleId", required = true) int ruleId,
			@RequestParam(value = "type", required = true) int type) {
		 if(type==1){
			//活动
			try{
				// 活动介绍
				Map<String, Object> duceMap = mstCampaignBiz.getCampaignIntroduce(ruleId);
				Map<String,Object> resultMap=new HashMap<String,Object>();
				if(duceMap!=null){
					resultMap.put("ruleId", duceMap.get("campaignId"));
					resultMap.put("goodsType", 1);
					resultMap.put("buyDate", "");
					resultMap.put("addressId", 0);
					resultMap.put("pickUpAway", 0);
					resultMap.put("quantity", 1);
					return new Success(resultMap);
				}else{
					return new Success(duceMap);
				}
				
			}catch (Exception e) {
				e.printStackTrace();
				return new Failure("系统异常");
			}
		}else if(type==2){
			//课程
			try{
				MstConclusionabout mstConclusionabout = aboutScheduleBiz.getScheduleDuce(ruleId);
				Map<String,Object> resultMap=new HashMap<String,Object>();
				if(mstConclusionabout!=null){
					resultMap.put("ruleId", ruleId);
					resultMap.put("goodsType", 2);
					resultMap.put("buyDate", "");
					resultMap.put("addressId", 0);
					resultMap.put("pickUpAway", 0);
					resultMap.put("quantity", 1);
					return new Success(resultMap);
				}else{
					return new Success(new ModelMap());
				}
			}catch (Exception e) {
				e.printStackTrace();
				return new Failure("系统异常");
			}
		}else if(type==3 || type==4 || type==5){
			try{
				Map<String, Object> paraMap = new HashMap<String, Object>();
				paraMap.put("goodsType", type);
				paraMap.put("ruleId", ruleId);
				Map<String, Object> ruleMap = mstFoodBiz.getMstRuleDetail(paraMap);
				Map<String,Object> resultMap=new HashMap<String,Object>();
				if(ruleMap!=null){
					resultMap.put("ruleId", ruleId);
					resultMap.put("goodsType", type);
					resultMap.put("buyDate", new SimpleDateFormat("MM-dd").format(new Date()));
					resultMap.put("addressId", 0);
					resultMap.put("pickUpAway", 1);
					resultMap.put("quantity", 1);
					return new Success(resultMap);
				}else{
					return new Success(new ModelMap());
				}
			}catch (Exception e) {
				e.printStackTrace();
				return new Failure("系统异常");
			}
		}
		return new Failure("未知的商品类型");
	}
}
